---
title: Filtering by Date
description: Learn how to filter your search results by date.
keywords: date, filter, date filtering
---

You can filter your search results by date. This is useful if you want to find all the documents that were created or modified in a specific time period.

## Setup a date field

To filter by date, you need to add a date field to your index. You can do this by adding a date field to your schema. 

Indexing the following document into Elasticsearch will create a date field called `date`:

```json
 {
   "date": "2015-01-01"
 }
```

and your mapping will look like this:

```json
{
  "properties": {
    "date": {
      "type": "date"
    }
  }
}
```

## Filter Attribute Configuration

Add a filter attribute to your index configuration. The filter attribute will be used to filter your search results by date.

```ts
 {
  "filter_attributes": [
    { attribute: 'date', field: 'date', type: 'date' },
  ]
 }
```
## NumericFilters Usage

If you want to filter by date using `numericFilters`, for example having a component adjusting the filters, you can use the following syntax:

```
numericFilters: [
  `availabilities.start<=${(new Date("2015-01-01")).getTime())}`, 
  `availabilities.end<=${(new Date("2019-01-01")).getTime())}`
]
```

See [camping-sites-demo](/camping-sites-demo) for an example of a date numeric filter component example.

## Using Filter Attributes

You can use the filter attribute in your search query to filter your search results by date within `configure`.

### Syntax Examples

```js
 "date:2015-01-01" # date is 2015-01-01
 "date:[2015-01-01 TO 2015-12-31]" # date is between 2015-01-01 and 2015-12-31
 "date:[2015-01-01 TO *]" # date is greater than 2015-01-01
 "date:[* TO 2015-12-31]" # date is less than 2015-12-31
```

### With configure

```js
 client.configure({
  filters: 'date:[2015-01-01 TO 2015-12-31]'
 })
```


